<?php
if(file_exists(WF::getWidgetPoolFactory()->getWPHome()."/inc/config.php")){
    require(WF::getWidgetPoolFactory()->getWPHome()."/inc/config.php");
}else{ //Update failed, Auto change /path/to/widgetPool/config.php define('WP_HOME','/path/to/wpFailLogId') => define('WP_HOME','/path/to/wpLastSuccessLogId')
    $strPathDir = dirname(__FILE__).'/../repository/widgetPool/*';
    $arrDir = glob($strPathDir, GLOB_ONLYDIR);
    if (is_array($arrDir) && $arrDir) {
        $maxWpLogId = 0;
        foreach ($arrDir as $strFullPathDir) {
            $intWpLogId = substr(basename($strFullPathDir),2);
            if($intWpLogId > $maxWpLogId){
                $maxWpLogId = $intWpLogId;
            }
        }
    }
    $intLogIdLastSuccess = $maxWpLogId;
    WF::getWidgetPoolFactory()->setWPHomeByLogId($intLogIdLastSuccess);
    $isSuccess = WF::getWidgetPoolFactory()->getWidgetPoolManager()->changeCurrentPathToWPLogId($intLogIdLastSuccess);
    if($isSuccess){
        echo '<script>window.location.reload();</script>';
    }
    exit();
}